package com.liushuai.phoneguardian.adapter;

import com.liushuai.phoneguardian.R;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class HomeAdapter extends BaseAdapter {

	private static final String[] names = { "手机防盗", "通讯卫士", "软件管理", "进程管理",
			"流量统计", "病毒查杀", "系统优化", "高级工具", "设置中心" };

	private static final int[] icons = { R.drawable.safe,
			R.drawable.callmsgsafe, R.drawable.app, R.drawable.taskmanager,
			R.drawable.netmanager, R.drawable.trojan, R.drawable.sysoptimize,
			R.drawable.atools, R.drawable.settings };
	private Context context;
	
	
	public HomeAdapter(Context context) {
		super();
		this.context=context;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return names.length;
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = View.inflate(context, R.layout.item_grid_home, null);
		TextView textView = (TextView) view.findViewById(R.id.tv_home_name);
		ImageView imageView = (ImageView) view.findViewById(R.id.iv_home_icon);
		textView.setText(names[position]);
		imageView.setImageResource(icons[position]);
		if(position==0){
			SharedPreferences sp = context.getSharedPreferences("config", context.MODE_PRIVATE);
			String newname=sp.getString("newname", "");
			if(!TextUtils.isEmpty(newname)){
				textView.setText(newname);
			}
		}
		return view;
	}

}
